<!--历史数据-->
<template>
  <div class="ele-body">
    <!-- 搜索表单 -->
    <div class="block-interval">
      <a-card :bordered="false">
        <a-form layout="inline" :model="where">
          <a-row>
            <a-form-item label="开始时间:">
              <a-date-picker v-model:value="where.searchBeginTime" type="date" show-time format="YYYY-MM-DD HH:mm:ss" valueFormat="YYYY-MM-DD HH:mm:ss" />
            </a-form-item>
            <a-form-item label="结束时间:">
              <a-date-picker v-model:value="where.searchEndTime" type="date" show-time format="YYYY-MM-DD HH:mm:ss" valueFormat="YYYY-MM-DD HH:mm:ss" />
            </a-form-item>
            <a-form-item class="ele-text-center">
              <a-space>
                <a-button type="primary" @click="reload">查询</a-button>
                <a-button @click="reset">重置</a-button>
              </a-space>
            </a-form-item>

          </a-row>
        </a-form>
      </a-card>
    </div>

    <!-- 表格 -->
    <div>
      <a-card :bordered="false">
        <ele-pro-table
          ref="table"
          row-key="vedId"
          :datasource="datasource"
          :columns="columns"
          :where="where"
          :scroll="{ x: 'max-content' }"
        >

          <template #bodyCell="{ column, record }">
            <!-- table操作栏按钮 -->
            <template v-if="column.key === 'action'">
              <a-space>
                <a-popconfirm title="确定要删除此记录吗？" @confirm="remove(record)">
                  <a class="ele-text-danger">删除</a>
                </a-popconfirm>
              </a-space>
            </template>
          </template>
        </ele-pro-table>
      </a-card>
    </div>

  </div>
</template>

<script>
import { message } from 'ant-design-vue';
import {VehicleEventDataApi} from "@/api/property/vechile/VehicleEventDataApi";


export default {
  name: 'VehicleManagerRunningstateManagerStateEventData',
  components: {
  },
  props: {
    data: Object
  },
  data() {
    return {
      // 表格列配置
      columns: [
        {
          title: '时间',
          dataIndex: 'sendtime'
        },
        {
          title: '事件',
          dataIndex: 'eventType',
          customRender: function (row) {
            if (row.text == 'GTPNA') {
              return '通电';
            } else if (row.text == 'GTPFA') {
              return '断电';
            } else if (row.text == 'GTIGN') {
              return '车辆点火启动';
            } else if (row.text == 'GTIGF') {
              return '车辆熄火';
            } else if (row.text == 'GTIDN') {
              return '车辆进入空转';
            } else if (row.text == 'GTIDF') {
              return '车辆退出空转';
            } else if (row.text == 'GTSTR') {
              return '进入启动状态';
            } else if (row.text == 'GTSTP') {
              return '进入停止状态';
            } else if (row.text == 'GTSTP' || row.text == 'GTLSP') {
              return '进入停止状态';
            } else if (row.text == 'GTFLA') {
              return '异常油耗告警';
            } else if (row.text == 'GTTMP') {
              return '温度告警';
            } else if (row.text == 'GTGIN') {
              return '进入围栏告警';
            } else if (row.text == 'GTGOT') {
              return '超出围栏告警';
            }
          }
        },
        {
          title: '操作',
          key: 'action',
          width: 280,
          align: 'center'
        }
      ],
      // 表格搜索条件
      where: {"vehicleId" : this.data.vehicleId, orderBy : "sendtime", sortBy : "desc"},
      // 当前编辑数据
      current: null,
    }
  },
  methods: {
    /**
     * 搜索按钮
     *
     * @author cancan
     * @date 2022/03/05 14:48
     */
    reload() {
      this.$refs.table.reload({ page: 1 });
    },

    /**
     * 重置搜索
     *
     * @author cancan
     * @date 2022/03/05 14:48
     */
    reset() {
      this.where.vehicleId = this.data.vehicleId;
      this.where.orderBy = "sendtime";
      this.where.sortBy = "desc";
      this.where.searchBeginTime = '';
      this.where.searchEndTime = '';
      this.$nextTick(() => {
        this.reload();
      });
    },

    /**
     * 删除
     *
     * @author cancan
     * @date 2022/03/05 14:48
     */
    async remove(row) {
      const result = await VehicleEventDataApi.delete({ vedId: row.vrsId });
      message.success(result.message);
      this.reload();
    },
    /**
     * 获取表格数据
     *
     * @author fengshuonan
     * @date 2022/5/8 15:18
     */
    datasource({ page, limit, where, orders }) {
      return VehicleEventDataApi.findPage({ ...where, ...orders, pageNo: page, pageSize: limit });
    }
  }
};
</script>
